package com.wolf.cx330.view.frag

import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.fragment.app.Fragment
import com.wolf.cx330.R
import com.wolf.cx330.base.dp
import kotlinx.android.synthetic.main.frag_circle_radius_anim.*

class CircleRadiusAnimFrag : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = inflater.inflate(R.layout.frag_circle_radius_anim, container, false)

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        val radiusAnim =
            ObjectAnimator.ofFloat(fcrACircleView, "radius", 0F.dp(), 100F.dp()).apply {
                repeatCount = ObjectAnimator.INFINITE
                repeatMode = ObjectAnimator.REVERSE
                interpolator = AccelerateDecelerateInterpolator()
            }

        val cAlphaAnim = ObjectAnimator.ofInt(fcrACircleView, "cAlpha", 0, 255).apply {
            repeatCount = ObjectAnimator.INFINITE
            repeatMode = ObjectAnimator.REVERSE
            interpolator = AccelerateDecelerateInterpolator()
        }

        AnimatorSet().apply {
            playTogether(radiusAnim, cAlphaAnim)
            duration = 1000
            start()
        }
    }
}